

import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Scanner;

import Boundary.MainGUI;
import Controller.ServerAccessManager;

import client.ServerAccess;
import xml.Message;

/** Launch the Client Application, some code get from When2Meet Source Code
 * 
 * @author zhaolongli
 *
 */

public class ClientLauncher {


	public static void main(String[] args) throws Exception {
		// FIRST thing to do is register the protocol being used. There will be a single class protocol
		// that will be defined and which everyone will use. For now, demonstrate with skeleton protocol.
		if (!Message.configure("decisionLines.xsd")) {
			System.exit(0);
		}
		
		ServerAccess sa = new ServerAccess("localhost");
		sa.connect(new DecisionLinesMessageHandler());
		ServerAccessManager.setAccess(sa);
		
		// send an introductory connect request 
		Message m = new Message ("<request id='123'><connectRequest/></request>");
		
		sa.sendRequest(m);
		
		MainGUI mg = new MainGUI();
		mg.setVisible(true);

		mg.addWindowListener(new WindowAdapter() {
			@Override
			public void windowClosing(WindowEvent we) {
				System.out.println("Client Disconnected.");
				ServerAccessManager.getAccess().disconnect();
				ServerAccessManager.setAccess(null);
			}
			
		});
	}

} 
